namespace JGSY.CMS.LowCode.Platform.Application.DTOs.Monitoring;

/// <summary>
/// 监控仪表板数据传输对象
/// </summary>
public class MonitoringDashboardDto
{
    /// <summary>
    /// 摘要信息
    /// </summary>
    public DashboardSummaryDto Summary { get; set; } = new();

    /// <summary>
    /// 性能趋势数据
    /// </summary>
    public List<PerformanceTrendDto> PerformanceTrends { get; set; } = new();

    /// <summary>
    /// 错误统计数据
    /// </summary>
    public ErrorStatisticsDto ErrorStatistics { get; set; } = new();

    /// <summary>
    /// 会话分析数据
    /// </summary>
    public SessionAnalysisDto SessionAnalysis { get; set; } = new();
}

/// <summary>
/// 仪表板摘要信息
/// </summary>
public class DashboardSummaryDto
{
    /// <summary>
    /// 活跃会话数
    /// </summary>
    public int ActiveSessions { get; set; }

    /// <summary>
    /// 错误总数（最近24小时）
    /// </summary>
    public int TotalErrors { get; set; }

    /// <summary>
    /// 平均LCP（毫秒）
    /// </summary>
    public decimal AvgLCP { get; set; }

    /// <summary>
    /// 平均FID（毫秒）
    /// </summary>
    public decimal AvgFID { get; set; }

    /// <summary>
    /// 平均CLS
    /// </summary>
    public decimal AvgCLS { get; set; }

    /// <summary>
    /// 平均FCP（毫秒）
    /// </summary>
    public decimal AvgFCP { get; set; }

    /// <summary>
    /// 平均TTFB（毫秒）
    /// </summary>
    public decimal AvgTTFB { get; set; }
}

/// <summary>
/// 性能趋势数据点
/// </summary>
public class PerformanceTrendDto
{
    /// <summary>
    /// 时间点
    /// </summary>
    public DateTime Time { get; set; }

    /// <summary>
    /// LCP数值
    /// </summary>
    public decimal LCP { get; set; }

    /// <summary>
    /// FID数值
    /// </summary>
    public decimal FID { get; set; }

    /// <summary>
    /// CLS数值
    /// </summary>
    public decimal CLS { get; set; }

    /// <summary>
    /// 样本数量
    /// </summary>
    public int SampleCount { get; set; }
}

/// <summary>
/// 错误统计数据
/// </summary>
public class ErrorStatisticsDto
{
    /// <summary>
    /// 按类型分组的错误数量
    /// </summary>
    public Dictionary<string, int> ByType { get; set; } = new();

    /// <summary>
    /// 按严重程度分组的错误数量
    /// </summary>
    public Dictionary<string, int> BySeverity { get; set; } = new();

    /// <summary>
    /// 最近错误列表
    /// </summary>
    public List<RecentErrorDto> RecentErrors { get; set; } = new();
}

/// <summary>
/// 最近错误信息
/// </summary>
public class RecentErrorDto
{
    /// <summary>
    /// 错误ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 错误类型
    /// </summary>
    public string ErrorType { get; set; } = string.Empty;

    /// <summary>
    /// 错误消息
    /// </summary>
    public string? ErrorMessage { get; set; }

    /// <summary>
    /// 页面URL
    /// </summary>
    public string PageUrl { get; set; } = string.Empty;

    /// <summary>
    /// 严重程度
    /// </summary>
    public string Severity { get; set; } = string.Empty;

    /// <summary>
    /// 发生次数
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 最后发生时间
    /// </summary>
    public DateTime LastOccurred { get; set; }
}

/// <summary>
/// 会话分析数据
/// </summary>
public class SessionAnalysisDto
{
    /// <summary>
    /// 今日会话数
    /// </summary>
    public int TodaySessions { get; set; }

    /// <summary>
    /// 平均会话时长（分钟）
    /// </summary>
    public decimal AvgSessionDuration { get; set; }

    /// <summary>
    /// 跳出率（%）
    /// </summary>
    public decimal BounceRate { get; set; }

    /// <summary>
    /// 设备类型分布
    /// </summary>
    public Dictionary<string, int> DeviceDistribution { get; set; } = new();

    /// <summary>
    /// 浏览器分布
    /// </summary>
    public Dictionary<string, int> BrowserDistribution { get; set; } = new();
}
